package top.laoshuzi.designpatterns.base.structure.flyweight;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 */
public class FlyweightFactory {

    private static final Map<String, Flyweight> map = new HashMap<>();

    public static Flyweight getFlyweight(String key) {

        Flyweight flyweight = map.get(key);
        if (flyweight == null) {
            flyweight = new ConcreteFlyweight();
            map.put(key, flyweight);
        }
        return flyweight;

    }

}
